import { ExtendsDocumentListStore } from './document-list.state.base';

export class DocumentListActions {
  static generateActionObject<T extends { id: string; documentId: string }>(
    fn: string,
    store: ExtendsDocumentListStore<T>,
    payload?: any
  ) {
    const name = store['NGXS_META'].path;
    const ReflectedAction = function (data: T) {
      this.payload = data;
    };
    const obj = new ReflectedAction(payload);
    obj.__proto__.constructor.type = `[${name}] ${fn}`;
    return obj;
  }

  static GetModels(store: ExtendsDocumentListStore<any>, payload: any): any {
    return DocumentListActions.generateActionObject('getModels', store, payload);
  }

  static TargetModelSelect(store: ExtendsDocumentListStore<any>, payload: any): any {
    return DocumentListActions.generateActionObject('targetModelSelect', store, payload);
  }

  static TargetAllSelect(store: ExtendsDocumentListStore<any>): any {
    return DocumentListActions.generateActionObject('targetAllSelect', store);
  }

  static ClearSelect(store: ExtendsDocumentListStore<any>): any {
    return DocumentListActions.generateActionObject('clearSelect', store);
  }

  static Delete(store: ExtendsDocumentListStore<any>): any {
    return DocumentListActions.generateActionObject('delete', store);
  }
}
